﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Club
{
    public partial class ViewFacilities : System.Web.UI.Page
    {
        BLL.BookFacility bookFacility = new BLL.BookFacility();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Dictionary<string, object> sessionVar = (Dictionary<string, object>)Session["vars"];
                DAL.User user = (DAL.User)sessionVar["userVar"];
                if (user == null)
                {
                    Response.Redirect("Default.aspx?prepage=ViewFacilities.aspx");
                }

                if (!IsPostBack)
                {
                    GridView1.DataSource = bookFacility.getFacilitiesList();
                    GridView1.DataBind();
                    GridView1.Columns[0].Visible = false;
                }
            }
            catch (Exception ex)
            {
                WebCommon.ShowMsg(Response, ex.Message);
            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                DAL.Facility facility = bookFacility.getFacility(Convert.ToInt32(((Label)(GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].FindControl("Label1"))).Text.ToString()));
                Dictionary<string, object> sessionVar = (Dictionary<string, object>)Session["vars"];
                sessionVar["facility"] = facility;
                Session["vars"] = sessionVar;
            }
            catch (Exception ex)
            {
                WebCommon.ShowMsg(Response, ex.Message);
            }
            Response.Redirect("Booking.aspx");
        }

    }
}